﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Security.Cryptography;
using NetworkLibrary;

namespace ServerTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        Server server;

        private void button1_Click(object sender, EventArgs e)
        {
        }

        private void button2_Click(object sender, EventArgs e)
        {
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            server = new Server(new RSAParameters(), new RSAParameters());
            server.OnClientConnected += new Common.OnClientConnected(server_OnClientConnected);
            server.OnDataReceived += new Common.DataReceived(server_OnDataReceived);
        }

        void server_OnClientConnected(NetworkClient client)
        {
            MessageBox.Show(client.ClientName);
        }

        void server_OnDataReceived(NetworkData networkData)
        {
            if(networkData.DataType == 0)
                MessageBox.Show(Encoding.ASCII.GetString(networkData.Data));
        }

        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            server.Shutdown();
        }
    }
}
